package com.xcity.game.combat.skill.impl;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.ActionEffect.Value;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.skill.Skill;

/**
 * 固若金汤<br/>
 * 为随机一名我方员工包括自己套上护盾，该护盾可以抵御玩家耐力*{0=1.25#0}的伤害，当护盾被击破时护盾持有者获得防御力+{1=50#0}点的状态，持续{2=2#0}回合
 * @author yang.li
 *
 */
public class COMBAT_SKILL_100001 extends CombatSkill {

	public COMBAT_SKILL_100001(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		CombatUnit target = source.getTeam().getUnitRandomly();
		action.addBuff(new BUFF(skill, target));
	}
	
	// 护盾
	static class BUFF extends CombatBuff {
		int hp;
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner);
//			this.hp = (int) (owner.getSTR() * template.getInitVal(0));
			this.hp = (int) (owner.getHp() * skill.getParameter(0));
		}
		@Override
		public void roundStart(Round round) {
		}
		@Override
		public void preDamage(ActionEffect effect) {
			active = true;
			int delta = effect.getHpDelta();
			if (delta < 0 && hp > 0) {
				hp += delta;
				Value v = effect.getValue(CombatAttributeType.HP);
				v.setDelta(hp > 0 ? 0 : hp);
			}
		}
		@Override
		public void roundEnd(Round round) {
			if (hp <= 0) { // 破盾
				uneffect();
				round.addBuff(this);
			}
		}
		@Override
		public void preAction(Action action) {
		}
	}

}
